package skills.jssvc.deu.cn.skillsecond.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import skills.jssvc.deu.cn.skillsecond.MyApplication;
import skills.jssvc.deu.cn.skillsecond.R;
import skills.jssvc.deu.cn.skillsecond.entry.Road;

/**
 * Created by Administrator on 2019/3/12 0012.
 */

public class Frag2RoadAdapter extends RecyclerView.Adapter<Frag2RoadAdapter.ViewHolder> {
    private List<Road> roadList = new ArrayList<>();

    public Frag2RoadAdapter(List<Road> roadList) {
        this.roadList = roadList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(MyApplication.appContext).inflate(R.layout.item_frag2_redmang, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Road road = roadList.get(position);
        holder.roadTv.setText(String.valueOf(road.getRoad()));
        holder.redTv.setText(String.valueOf(road.getRedTime()));
        holder.yellowTv.setText(String.valueOf(road.getYellowTime()));
        holder.greenTv.setText(String.valueOf(road.getGreenTime()));
    }

    @Override
    public int getItemCount() {
        return roadList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView roadTv;
        private TextView redTv;
        private TextView yellowTv;
        private TextView greenTv;
        public ViewHolder(View itemView) {
            super(itemView);
            roadTv = (TextView) itemView.findViewById(R.id.item_frag2_roadid_tv);
            redTv = (TextView) itemView.findViewById(R.id.item_frag2_redtime_tv);
            yellowTv = (TextView) itemView.findViewById(R.id.item_frag2_yellowtime_tv);
            greenTv = (TextView) itemView.findViewById(R.id.item_frag2_greentime_tv);
        }
    }
}
